﻿using System;
using Kooboo.CMS.Caching;
using System.Runtime.Caching;
namespace KB
{
    public class CacheUtility
    {
        public static object Get(string key)
        {
            return CacheManagerFactory.DefaultCacheManager.GlobalObjectCache().Get(key);
        }

        public static bool Add(string key, object value)
        {
            return CacheManagerFactory.DefaultCacheManager.GlobalObjectCache().Add(key, value, DefaultCacheItemPolicy);
        }

        public static bool Add(string key, object value, TimeSpan ts)
        {
            return CacheManagerFactory.DefaultCacheManager.GlobalObjectCache().Add(key, value, new CacheItemPolicy() { SlidingExpiration = ts });
        }


        public static bool Add(string key, object value, DateTimeOffset dt)
        {
            return CacheManagerFactory.DefaultCacheManager.GlobalObjectCache().Add(key, value, new CacheItemPolicy() {  AbsoluteExpiration = dt });
        }

        public static void Clear(string key)
        {
            CacheManagerFactory.DefaultCacheManager.GlobalObjectCache().Remove(key);
        }

        public static CacheItemPolicy DefaultCacheItemPolicy = new CacheItemPolicy()
        {
            SlidingExpiration = TimeSpan.Parse("00:30:00"),
        };

    }
}
